Imports System.Collections

Partial Class pages_sets_usercontrols_UCSet : Inherits UserControl

#Region "Members"
    Private m_child As CProduct
    Private m_sortedList As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal child As CProduct, sortedList As IList)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_child = child
        m_sortedList = sortedList
        btnMoveUp.Visible = sortedList.Count > 1
        btnMoveDn.Visible = sortedList.Count > 1
        With m_child
            litNumber.Text = CStr(sortedList.IndexOf(m_child) + 1)

            lnkSetChildProductId.Text = CUtilities.Truncate(.ProductName)
            lnkSetChildProductId.ToolTip = .ProductName
            lnkSetChildProductId.NavigateUrl = CSitemap.ProductEdit(.ProductId)
            If .ShowDate Then lnkSetChildProductId.Text &= (" " & .DateString)

            lnkFiles.Text = .Contents
            lnkFiles.ToolTip = .Files.NamesAndSizes
            lnkFiles.NavigateUrl = CSitemap.ProductFiles(.ProductId)

            litPrice.Text = CTextbox.SetMoney(.ProductPrice)
            chkActive.Checked = .ProductIsActive

            lnkTranscript.NavigateUrl = CSitemap.ProductTranscription(.ProductId)
            If .HasTranscript Then
                lnkTranscript.Text = CUtilities.Truncate(.ScribeName, 20)
                lnkTranscript.ToolTip = CUtilities.Truncate(.ProductTranscription)
            ElseIf .ProductType.TypeCanHaveTranscript Then
                lnkTranscript.Text = "+Trans"
                lnkTranscript.ToolTip = "Add " & lnkTranscript.ToolTip
            End If

            lnkVimeo.NavigateUrl = CSitemap.ProductVimeo(.ProductId)
            If .ProductVimeoId > 0 Then
                lnkVimeo.Text = .ProductVimeoId
            ElseIf Not String.IsNullOrEmpty(.ProductYouTubeId) Then
                lnkVimeo.Text = .ProductYouTubeId
            ElseIf .ProductType.TypeCanHaveVimeo Then
                lnkVimeo.Text = "+Vimeo"
                lnkVimeo.ToolTip = "Add " & lnkVimeo.ToolTip
            End If

            If .ProductType.TypeParentIsRequired Then
                btnDelete.ToolTip = "Delete permanently"
                btnDelete.OnClientClick = "return confirm('Are you sure that you want to permanently delete this Product?')"
            End If
        End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub btnMoveUp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnMoveUp.Click
        With New CProductList(m_sortedList)
            .MoveUp(m_child)
        End With
        Refresh()
    End Sub
    Private Sub btnMoveDn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnMoveDn.Click
        With New CProductList(m_sortedList)
            .MoveDown(m_child)
        End With
        Refresh()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        If m_child.ProductType.TypeParentIsRequired Then
            m_child.Delete()
        Else
            m_child.ProductBelongsToProductId = Integer.MinValue
            m_child.Save()
        End If
        Refresh()
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_set.SetParentId, MyParent.ETab.sets, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
